/*
 * Copyright (c) 2024 SwanLink (Jiangsu) Technology Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific path governing permissions and
 * limitations under the License.
 */

#ifndef NATIVE_FILE_SHARE_CONFIG_H
#define NATIVE_FILE_SHARE_CONFIG_H

#include <string>
#include <map>
#include <memory>

#include "file_share_errors.h"
#include "file_share_log.h"
#include "preferences_helper.h"
#include "preferences.h"
#include <thread>
#include <chrono>
namespace OHOS {
namespace FileShare {
class FileShareConfig {
public:
    static FileShareConfig &GetInstance();
public:
    std::string GetStoragePath();
    int32_t SetStoragePath(std::string &path);
    int32_t GetWorkDuration();
    int32_t SetWorkDuration(int32_t &time);
    void CountdownTimer(uint32_t totalSeconds);
    void StartTimer();
    void StopTimer();
    void RegisterCallback(std::function<void(void)> func);
private:
    FileShareConfig() = default;
    ~FileShareConfig() = default;
    std::shared_ptr<NativePreferences::Preferences> GetFileSharePreferences();
    bool IsExistDir(const char *path);
    bool MkOwnerDir(const char *dir);
    std::mutex mutex_;
    std::atomic<bool> isCountingDown_;
    std::atomic<bool> cancelFlag_;
    std::thread timerThread_;
    std::function<void(void)> callbackFun_ = nullptr;
};    

} // namespace FileShare
} // namespace OHOS

#endif // NATIVE_FILE_SHARE_CONFIG_H